package com.qf.service.impl;

import com.alibaba.fastjson.JSON;
import com.qf.common.R;
import com.qf.mapper.ProvinceMapper;
import com.qf.mapper.impl.ProvinceMapperImpl;
import com.qf.pojo.City;
import com.qf.pojo.Province;
import com.qf.service.ProvinceService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class ProvinceServiceImpl implements ProvinceService {

    private ProvinceMapper provinceMapper = new ProvinceMapperImpl();

    @Override
    public void getProvinces(HttpServletRequest request, HttpServletResponse response) throws IOException {

        List<Province> provinces = provinceMapper.getProvinces();
        String jsonStr = JSON.toJSONString(R.success("获取成功", provinces));
        response.getWriter().write(jsonStr);
    }

    @Override
    public void getCities(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //获取省份的code
        String code = request.getParameter("code");
        List<City> cities = provinceMapper.getCities(code);
        String jsonStr = JSON.toJSONString(R.success("获取成功", cities));
        response.getWriter().write(jsonStr);
    }
}
